<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
class Sms{
	
    function __construct()
    {
        require_once(APPPATH.'libraries/sms/SmsApi.php');
        $this->ci =& get_instance();
        $this->clapi  = new SmsApi();
        $this->ci->load->model('sms_model');
        $this->sign = "【弹溜溜】";
        
    }
    /**
     * 短信发送 $mobiles=array() 数组,  最多为200个手机号码
     */
    function sendSMS($mobiles=array(),$vcode,$content,$ip)
    {
        
        $count = $this->ci->sms_model->get_count(array('account'=>$mobiles,'status'=>0,'create_date'=>  date('Ymd'),'send_type'=>1));
        $mess = array();
        if(count > 10){
            $mess['info'] = '今天请求短信验证已达到上限，请明天再试';
            $mess['status'] = '1';
            return $mess;
        }
        
//      $content = $this->sign.$content;
        $result = $this->clapi->sendSMS($mobiles,$content,'true');
        $result = $this->clapi->execResult($result);
        $data = array();
        $data['account'] = $mobiles;
        $data['code'] = $vcode;
        $data['content'] = $content;
        $data['status'] = $result[1];
        $data['type'] = 1;
        $data['send_type'] = 1;
        $data['ip'] = $ip;
        $data['create_date'] = date("Ymd");
        $data['create_time'] = time();
        $this->ci->sms_model->insert($data);
        if($result[1] == 0){
            $mess['info'] = '短信已发送';
            $mess['status'] = 0;
            return $mess;
        }else{
            $mess['info'] = '短信发送失败';
            $mess['status'] = $result[1];
            return $mess;
        }
    }
	
    /**
     * 余额查询
     */
    function getBalance()
    {

            $result = $this->clapi->queryBalance();
            $result = $this->clapi->execResult($result);
            switch($result[1]){
                case 0:
                        return "剩余{$result[3]}条";
                        break;
                case 101:
                        return '无此用户';
                        break;
                case 102:
                        return '密码错';
                        break;
                case 103:
                        return '查询过快';
                        break;
        }
    }

    /**
     * 得到状态报告
     */
//	function getReport()
//	{
//		return $this->client->getReport();
//		
//	}
	
	
	
	
}